package org.example.product.config;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class FileUploadUtils {

    public static List<Path> getUploadDirectories(String child, String targetChild) throws FileNotFoundException {
        // 获取 resources 目录
        String resourcesPath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" + File.separator + "resources";

        // 拼接开发和生产路径
        Path devPath = Paths.get(resourcesPath, child);
        Path targetPath = Paths.get(System.getProperty("user.dir"), "target", targetChild);

        // 创建目录
        createDirectory(devPath);
        createDirectory(targetPath);

        List<Path> paths = new ArrayList<>();
        paths.add(devPath);
        paths.add(targetPath);

        return paths;
    }

    private static void createDirectory(Path path) {
        try {
            if (!Files.exists(path)) {
                Files.createDirectories(path);
            }
        } catch (IOException e) {
            throw new RuntimeException("创建目录失败：" + path.toString(), e);
        }
    }
}
